<%@page import="java.util.Hashtable"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Enumeration" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<link href="${pageContext.request.contextPath}/css/org_manager.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/add_new_org.css"
	rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/test_mark2.css"
	rel="stylesheet" type="text/css" />
<jsp:useBean id="testBean"
	class="team02.server.bean.TestBean" scope="page"></jsp:useBean>
	<jsp:useBean id="markBean"
	class="team02.server.bean.MarkBean" scope="session"></jsp:useBean>
<script>
function error(){
	alert("テストがまだ実施しません");
	window.location="test_manager.t02";
}
</script>
<div class="menu1"><%@include file="/jsputils/menu.jsp"%>
	<div class = "greeting_message">
		<%@include file="/jsputils/greeting.jsp"%>
	</div>
</div>
<%
//権限をチェック
if(userBean.getAccessLevel()<2)
{
	response.sendRedirect("error.t02");
	return;
}
//tranh truy cap truc tiep
if(request.getMethod()=="GET")
{
	response.sendRedirect("test_manager.t02");
	return;
}
//khi an nut submit
if(request.getParameterMap().containsKey("save"))
{
	Enumeration names = request.getParameterNames();
	Hashtable htbl=new Hashtable();
	while(names.hasMoreElements())
	{
		String att=names.nextElement().toString();
		htbl.put(att, request.getParameter(att));
	}
	markBean.update(htbl);
	request.setAttribute("selected_id", request.getParameter("selected_id"));
	response.sendRedirect("test_mark.t02");
}
// load trang sau khi redirect tu test_mark.t02
else if(request.getParameterMap().containsKey("selected_id"))
{
	examineeBean.setId(Integer.parseInt(request.getParameter("selected_id")));
	examineeBean.load();
%>
<c:set value='<%=markBean.listQuestionAnswer(Integer.parseInt(request.getParameter("testId")),Integer.parseInt(request.getParameter("selected_id")))%>' var="listQuestionAnswer"></c:set>
<div class="container">
<form action="" method="post" name="form" class="table_content">
	<div class="menu">
		<p class="menu_label">テスト採点</p> 
	</div>
	<br><b>タイトル：<%=request.getParameter("testTitle") %></b><br>
	<b>サブタイトル：<%=request.getParameter("testSubTitle") %></b><br>
	<b>回答者名：<%=examineeBean.getName() %></b><br>
	<b>回答者ID：<%=examineeBean.getUsername() %></b><br><br><br>
		<c:forEach var="qaItem" items="${listQuestionAnswer}">
			<c:choose>
				<c:when
					test='${qaItem.question.getExaminerInsertType().equals("CINP") }'>
					<div class="question_CINP">
						<c:choose>
							<c:when test='${ qaItem.question.getType().equals("QS")}'>
								<b>問${qaItem.question.getQuestionNo() }:
									${qaItem.question.getContent()}</b>
								<c:set value='${qaItem.question.getSelectionList()}'
									var="listSelection"></c:set>
								<ol>
									<c:forEach var="sItem" items="${listSelection}">
										<li>${sItem.getContent()}</li>
									</c:forEach>
								</ol>
						回答：${qaItem.getExamineeSelection() }<br>
						タイム：${qaItem.question.getUsedTime() }ミリ秒<br>
						得点: <input type="text" maxlength="3" name="${qaItem.getMarkName() }"
									style="width: 20px" value="${qaItem.question.getScore() }">点
						コメント：<input type="text" name="${qaItem.getCmtName() }"
										value="${qaItem.question.getInsertContent()}"><br>
							</c:when>
							<c:when test='${ qaItem.question.getType().equals("QW")}'>
									<b>問${qaItem.question.getQuestionNo() }:
										${qaItem.question.getContent()}</b>
									<c:set value='${qaItem.question.getExamineeWrite() }'
										var="listWrite"></c:set>
									<ul>
										<c:forEach var="wItem" items="${listWrite}">
											<li><textarea rows="1" cols="50" readonly="readonly">${wItem}</textarea> </li>
										</c:forEach>
									</ul>
									得点: <input type="text" name="${qaItem.getMarkName() }"
										maxlength="3" style="width: 20px"
										value="${qaItem.question.getScore()}">点 <br>
									ヒント：<br>${qaItem.question.getAnswerScoreList() }<br>
									コメント：<input type="text" name="${qaItem.getCmtName() }"
										value="${qaItem.question.getInsertContent()}">
							</c:when>
						</c:choose>
					</div>
				</c:when>
				<c:otherwise>
					<div class="question_NORMAL">
					<c:choose>
						<c:when test='${ qaItem.question.getType().equals("QS")}'>
								<b>問${qaItem.question.getQuestionNo() }:
									${qaItem.question.getContent()}</b>
								<c:set value='${qaItem.question.getSelectionList()}'
									var="listSelection"></c:set>
								<ol>
									<c:forEach var="sItem" items="${listSelection}">
										<li>${sItem.getContent()}</li>
									</c:forEach>
								</ol>
								回答：${qaItem.getExamineeSelection() }<br> 
								タイム：${qaItem.question.getUsedTime() }ミリ秒<br>
								得点: <input type="text" style="width: 20px" value="${qaItem.question.getScore() }" readonly="readonly">点
								<br>
						</c:when>
						<c:when test='${ qaItem.question.getType().equals("QW")}'>
								<b>問${qaItem.question.getQuestionNo() }:
									${qaItem.question.getContent()}</b>
								<c:set value='${qaItem.question.getExamineeWrite() }'
									var="listWrite"></c:set>
								<ul>
									<c:forEach var="wItem" items="${listWrite}">
										<li><textarea rows="1" cols="50" readonly="readonly">${wItem}</textarea> </li>
									</c:forEach>
								</ul>
								得点: <input type="text" style="width: 20px" value="${qaItem.question.getScore() }" readonly="readonly">点 <br> 
						</c:when>
					</c:choose>
					</div>
				</c:otherwise>
			</c:choose>
		</c:forEach>
		<div class="submit">
	<input type="hidden" name="selected_id" value="<%=request.getParameter("testId")%>">
	<input type="hidden" name="examinee_id" value="<%=request.getParameter("selected_id")%>">
	<input type="submit" formaction="" name="save" value="保存"/>
	<input type="submit" formaction="test_mark.t02" value="キャンセル">
	</div>
</form>
</div>
<%
}
%>